package com.ds.common.route.agent;

import com.ds.common.nacos.ConfigModel;
import lombok.Data;
import lombok.Getter;

import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

public class AgentGroupList implements ConfigModel {

    @Getter
    Map<Integer, AgentGroup> agentGroupMap;

    List<AgentGroup> agentGroupList;

    public void setAgentGroupList(List<AgentGroup> agentGroupList) {
        this.agentGroupList = agentGroupList;
        if (agentGroupList != null) {
            agentGroupMap = agentGroupList.stream().collect(Collectors.toMap(AgentGroup::getAgentGroupId, Function.identity()));
        }
    }

    @Override
    public boolean isValid() {
        return agentGroupList != null && !agentGroupList.isEmpty() && agentGroupList.stream().allMatch(AgentGroup::isValid);
    }

    @Data
    public static class AgentGroup implements ConfigModel {
        Integer agentGroupId;
        String agentGroupName;
        String description;

        @Override
        public boolean isValid() {
            return agentGroupId != null && agentGroupName != null && description != null;
        }
    }
}
